<template>
  <div class="bindWarehouse-container app-container">
    <div class="filter-container">
      <el-input v-model="listQuery.mid_table_remark_003" placeholder="房源名称" clearable class="filter-item input-item"
        style="width: 200px;" @clear="handleFilter" @keyup.enter.native="handleFilter" />
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">
        搜索
      </el-button>
    </div>

    <el-table :key="tableKey" v-loading="listLoading" :data="list" border fit highlight-current-row style="width: 100%;">

      <el-table-column label="ID" prop="id" align="center" width="120" :class-name="getSortClass('id')">
        <template slot-scope="{row}">
          <span>{{ row.table_id_father }}</span>
        </template>
      </el-table-column>
      <el-table-column label="预览图" align="center">
        <template slot-scope="{row}">
          <el-image :src="row.mid_table_remark_002"></el-image>
        </template>
      </el-table-column>
      <el-table-column label="房源名称" align="center">
        <template slot-scope="{row}">
          <span>{{ row.mid_table_remark_003 || '-' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="房源类型" align="center">
        <template slot-scope="{row}">
          <span>{{ houseType[row.mid_table_remark_004] || '-' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="使用面积" align="center">
        <template slot-scope="{row}">
          <span>{{ row.mid_table_remark_006 ? `${row.mid_table_remark_006}m²` : '-' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="使用面积" align="center">
        <template slot-scope="{row}">
          <span>{{ row.mid_table_remark_008 ? `${row.mid_table_remark_008}元` : '-' }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="currentPage" :limit.sync="listQuery.limit"
      @pagination="getPageList" />
  </div>
</template>

<script>
import waves from '@/directive/waves' // waves directive
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import { getWarehouseList } from '@/api/warehouse'


export default {
  name: 'BindShop',
  components: { Pagination },
  directives: { waves },
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'info',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      houseType: {
        1001: "整租",
        1002: "合租",
        1003: "公寓",
        1004: "商铺",
        1005: "新房",
        1006: "二手房"
      },
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: true,
      currentPage: 0,
      listQuery: {
        invoke_method: 'public_load_middle_table_list',
        pre_db_para_middle_table_name: 'public_middle_table_lite_mod_interview_exam',
        type_middle_app: '14001',
        type_inner_app: '3003',
        is_online: '0',
        pre_db_para_begin_idx: '0',
        pre_db_para_length_4_list: '10',
        mid_table_remark_003_like: ''
      },
    }
  },
  created() {
    console.log(' create =====!!!')
    this.getList()
  },
  methods: {
    /*
    * 获取页面数据
    * */
    getList() {
      this.listLoading = true;
      getWarehouseList().then(response => {
        console.log(response)
        this.list = response.page_content
        this.total = response.result_num

        // Just to simulate the time of the request
        setTimeout(() => {
          this.listLoading = false
        }, 0.5 * 1000)
      })
    },
    /*
    * 点击分页进行查询
    * */
    getPageList(val) {
      this.listQuery.pre_db_para_begin_idx = (val.page - 1) * this.listQuery.pre_db_para_length_4_list
      this.getList()
    },
    /*
    * 查询数据
    * */
    handleFilter() {
      this.listQuery.pre_db_para_begin_idx = 0
      this.getList()
    },
    getSortClass: function (key) {
      const sort = this.listQuery.sort
      return sort === `+${key}` ? 'ascending' : 'descending'
    },

  }
}
</script>

<style lang="scss" scoped></style>
